// ignore_for_file: prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:multi_shop/widgets/goods.dart';
import 'package:get/get.dart';

/// 分类商品页面：展示某子分类下的商品列表
class CategoryProductsPage extends StatelessWidget {
  final String category;
  final String subCategory;

  const CategoryProductsPage({
    Key? key,
    required this.category,
    required this.subCategory,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 模拟商品数据
    final List<Map<String, dynamic>> products = List.generate(
      20,
      (i) => {
        'id': '$subCategory-$i',
        'imageUrl': 'https://picsum.photos/seed/$i/200/200',
        'name': '$subCategory 商品 #$i',
        'price': '${50 + i * 5}',
      },
    );

    return Scaffold(
      appBar: AppBar(title: Text('$subCategory')),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
        child: GridView.builder(
          itemCount: products.length,
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            crossAxisSpacing: 12,
            mainAxisSpacing: 12,
            childAspectRatio: 0.68,
          ),
          itemBuilder: (context, index) {
            final item = products[index];
            return ProductCard(
              imageUrl: item['imageUrl'],
              name: item['name']!,
              price: item['price']!,
              sales: item['sales']!,
              onTap: () {
                // 点击商品可跳转详情页
                Get.toNamed(
                  '/detail',
                  arguments: {
                    'id': item['id'],
                    'imageUrls': [item['imageUrl']],
                    'name': item['name'],
                    'description': '这里是$subCategory 商品 #$index 的详细描述。',
                  },
                );
              },
            );
          },
        ),
      ),
    );
  }
}
